--- /dev/null
+/*
+ Definitions for Garmin USB protocol and implementation.
+
+ Copyright (C) 2004 Robert Lipe, robertlipe@usa.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+#include <stdio.h>
+
+/* This structure is a bit funny looking to avoid variable length
+ * arrays which aren't present in C89. This contains the visible
+ * fields in the USB packets of the Garmin USB receivers (60C, 76C, etc.)
+ * All data are little endian.
+ */
+typedef
+union {
+ struct {
+ unsigned char type;
+ unsigned char reserved1;
+ unsigned char reserved2;
+ unsigned char reserved3;
+ unsigned char pkt_id[2];
+ unsigned char reserved6;
+ unsigned char reserved7;
+ unsigned char datasz[4];
+ unsigned char databuf[1]; /* actually an variable length array... */
+ } gusb_pkt;
+ unsigned char dbuf[MAX_GPS_PACKET_SIZE];
+} garmin_usb_packet;
+
+/*
+ * Internal interfaces that are common regardless of underlying
+ * OS implementation.
+ */
+#define GUSB_MAX_UNITS 20
+struct {
+ unsigned long serial_number;
+ char *os_identifier; /* In case the OS has another name for it. */
+ char *product_identifier; /* From the hardware itself. */
+} garmin_unit_info[GUSB_MAX_UNITS];
+
+int gusb_cmd_send(const garmin_usb_packet *obuf, size_t sz);
+int gusb_cmd_get(garmin_usb_packet *ibuf, size_t sz);
+int gusb_open(const char *portname);
+int gusb_close(void);
static void GPS_D551_Send(UC *data, GPS_PAlmanac alm);
-int32 gps_save_id;
-double gps_save_version;
-char gps_save_string[GPS_ARB_LEN];
+int32 gps_save_id;
+int gps_is_usb;
+double gps_save_version;
+char gps_save_string[GPS_ARB_LEN];
/* @func GPS_Init ******************************************************
int32 ret;
(void) GPS_Util_Little();
+
+ /*
+ * Decide here if the portname refers to a USB device and set the
+ * global that's used as in inflection point for other decisions later.
+ */
+ gps_is_usb = (0 == strncmp(port, "usb:", 4));
+
ret = GPS_A000(port);
if(ret<0) return ret;
-
+ if (gps_is_usb) return 1;
gps_save_time = GPS_Command_Get_Time(port);
if(!gps_save_time) {
return FRAMING_ERROR;
if(!GPS_Serial_On(port, &fd))
return gps_errno;
- if(!GPS_Serial_Flush(fd))
+ if(!gps_is_usb && !GPS_Serial_Flush(fd))
return gps_errno;
if(!(tra = GPS_Packet_New()) || !(rec = GPS_Packet_New()))
return MEMORY_ERROR;
-
+
GPS_Make_Packet(&tra, LINK_ID[0].Pid_Product_Rqst,NULL,0);
if(!GPS_Write_Packet(fd,tra))
return SERIAL_ERROR;
(void) sprintf(tstr,
"Version:\t%.2f\n",gps_save_version);
GPS_User(tstr);
-
-
gps_date_time_transfer = pA600;